<?php

namespace app\admin\command;

use app\admin\model\TaskJob;
use think\console\Command;
use think\Config;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
use think\Db;
use think\Exception;
use think\Log;


class AnalyzeJob extends Command {

    protected function configure() {
        $this->setName('analyzejob')
            ->setDescription('Analyze call job');
        $this->addArgument('jobid', Argument::REQUIRED, 'Call job id');
    }

    protected function doJobAnalysis($jobid) {

        //ToDo: 在这里分析处理call job，对外呼job进行评级

    }

    protected function markJobCompleted($jobid) {
        $job = TaskJob::get(['id' => $jobid]);
        if (empty($job)) {
            throw new Exception('编号为[' . $jobid . ']的任务JOB不存在');
        }
        $job->completed = 1;
        $job->save();
    }

    protected function execute(Input $input, Output $output) {
        $jobid = $input->getArgument('jobid');
        $this->markJobCompleted($jobid);
        $this->doJobAnalysis($jobid);
        echo "Call Job [{$jobid}] analysis completed!\n";
    }


}
